package com.collect.cameroon.zhiScene.zhiScriptLib;

import android.annotation.SuppressLint;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.collect.cameroon.R;
import com.collect.cameroon.zhiAdater.zhiScriptLib.ZHIScriptLibAdjuster;
import com.collect.cameroon.zhiBase.BaseActivity;
import com.collect.cameroon.zhiBean.zhiReceive.ZHIRScriptLibEntity;
import com.collect.cameroon.zhiBean.zhiReceive.ZHIRScriptLibListEntity;
import com.collect.cameroon.zhiBean.zhiSend.ZHISendEntity;
import com.collect.cameroon.zhiGlobal.zhiAppSettings.ZHIProjectRouter;
import com.collect.cameroon.zhiScene.zhiWidget.zhiNavigationBar.ZHINavigationBar;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

@SuppressLint("NonConstantResourceId")
@Route(path = ZHIProjectRouter.ZHI_Script_Library)
public class ZHIScriptLibActivity extends BaseActivity<ZHIScriptLibPresenter> implements ZHIScriptLibContract.View {

    @BindView(R.id.navigationBar)
    ZHINavigationBar navigationBar;
    @BindView(R.id.rc_list)
    RecyclerView rc_list;
    @BindView(R.id.rc_list_communication)
    RecyclerView rc_list_communication;

    @BindView(R.id.tv_home)
    TextView tv_home;
    @BindView(R.id.v_line_block_home)
    View v_line_block_home;

    @BindView(R.id.tv_basis)
    TextView tv_basis;
    @BindView(R.id.v_line_block_basis)
    View v_line_block_basis;

    @BindView(R.id.tv_solution)
    TextView tv_solution;
    @BindView(R.id.v_line_block_solution)
    View v_line_block_solution;

    @BindView(R.id.tv_special)
    TextView tv_special;
    @BindView(R.id.v_line_block_special)
    View v_line_block_special;

    private ArrayList<ZHIRScriptLibEntity> mHomeEntities;
    private ArrayList<ZHIRScriptLibEntity> mBasisEntities;
    private ArrayList<ZHIRScriptLibEntity> mSolutionEntities;
    private ArrayList<ZHIRScriptLibEntity> mSpecialCaseEntities;

    ZHIScriptLibAdjuster mZHIScriptLibAdjuster = new ZHIScriptLibAdjuster();
    ZHIScriptLibAdjuster mCTScriptLibComAdjuster = new ZHIScriptLibAdjuster("Communication");

    @Override
    protected void initInjector() {
        mActivityComponent.inject(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_script_lib_v2;
    }

    @Override
    protected void initView() {
        navigationBar.hideRight().setCenterText(getResources().getString(R.string.script_lib)).setBarClickListener(new ZHINavigationBar.OnNavigationBarClickListener() {
            @Override
            public void onNavigationBarLeftClick(View v) {
                finish();
            }

            @Override
            public void onNavigationBarRightClick(View v) {
            }
        });
        navigationBar.setLeftImgage(R.drawable.ic_91);
        navigationBar.showLeft();

        initEvent();
        initData();
    }

    @OnClick({R.id.tv_home, R.id.tv_basis, R.id.tv_solution, R.id.tv_special})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_home: {
                tv_home.setTextColor(getResources().getColor(R.color.theme_black_0));
                tv_basis.setTextColor(getResources().getColor(R.color.theme_black_3));
                tv_solution.setTextColor(getResources().getColor(R.color.theme_black_3));
                tv_special.setTextColor(getResources().getColor(R.color.theme_black_3));

                v_line_block_home.setBackgroundColor(getResources().getColor(R.color.theme_color_0));
                v_line_block_basis.setBackgroundColor(getResources().getColor(R.color.white));
                v_line_block_solution.setBackgroundColor(getResources().getColor(R.color.white));
                v_line_block_special.setBackgroundColor(getResources().getColor(R.color.white));

                mZHIScriptLibAdjuster.setNewData(mHomeEntities);
                break;
            }
            case R.id.tv_basis: {
                tv_home.setTextColor(getResources().getColor(R.color.theme_black_3));
                tv_basis.setTextColor(getResources().getColor(R.color.theme_black_0));
                tv_solution.setTextColor(getResources().getColor(R.color.theme_black_3));
                tv_special.setTextColor(getResources().getColor(R.color.theme_black_3));

                v_line_block_home.setBackgroundColor(getResources().getColor(R.color.white));
                v_line_block_basis.setBackgroundColor(getResources().getColor(R.color.theme_color_0));
                v_line_block_solution.setBackgroundColor(getResources().getColor(R.color.white));
                v_line_block_special.setBackgroundColor(getResources().getColor(R.color.white));

                mZHIScriptLibAdjuster.setNewData(mBasisEntities);
                break;
            }
            case R.id.tv_solution: {
                tv_home.setTextColor(getResources().getColor(R.color.theme_black_3));
                tv_basis.setTextColor(getResources().getColor(R.color.theme_black_3));
                tv_solution.setTextColor(getResources().getColor(R.color.theme_black_0));
                tv_special.setTextColor(getResources().getColor(R.color.theme_black_3));

                v_line_block_home.setBackgroundColor(getResources().getColor(R.color.white));
                v_line_block_basis.setBackgroundColor(getResources().getColor(R.color.white));
                v_line_block_solution.setBackgroundColor(getResources().getColor(R.color.theme_color_0));
                v_line_block_special.setBackgroundColor(getResources().getColor(R.color.white));

                mZHIScriptLibAdjuster.setNewData(mSolutionEntities);
                break;
            }
            case R.id.tv_special: {
                tv_home.setTextColor(getResources().getColor(R.color.theme_black_3));
                tv_basis.setTextColor(getResources().getColor(R.color.theme_black_3));
                tv_solution.setTextColor(getResources().getColor(R.color.theme_black_3));
                tv_special.setTextColor(getResources().getColor(R.color.theme_black_0));

                v_line_block_home.setBackgroundColor(getResources().getColor(R.color.white));
                v_line_block_basis.setBackgroundColor(getResources().getColor(R.color.white));
                v_line_block_solution.setBackgroundColor(getResources().getColor(R.color.white));
                v_line_block_special.setBackgroundColor(getResources().getColor(R.color.theme_color_0));

                mZHIScriptLibAdjuster.setNewData(mSpecialCaseEntities);
                break;
            }
            default:
                break;
        }
    }

    public void initEvent() {
        //设置空布局
        View emptyView = getLayoutInflater().inflate(R.layout.view_empty_no_data, null);
        emptyView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        emptyView.setOnClickListener(v -> {});

        mZHIScriptLibAdjuster.setEmptyView(emptyView);

        rc_list.setLayoutManager(new GridLayoutManager(getActivity(), 1));
        rc_list.setAdapter(mZHIScriptLibAdjuster);
    }

    /**
     * 设置数据源
     *
     * @type method
     * @author liwenjie
     * @creatTime 2019-11-05 09:52
     */
    public void initData() {
        if (mPresenter != null) {
            mPresenter.getAppWords(ZHIScriptLibActivity.this, new ZHISendEntity());
        }
    }

    @Override
    public void onGetErrorInfo() {

    }

    @Override
    public void onGetAppWords(ZHIRScriptLibListEntity zhirScriptLibListEntity) {
        try {
            mBasisEntities = zhirScriptLibListEntity.getBASIS();
            mSolutionEntities = zhirScriptLibListEntity.getSOLUTION();
            mSpecialCaseEntities = zhirScriptLibListEntity.getSPECIAL_CASES();
            mHomeEntities = zhirScriptLibListEntity.getHOME();
            mZHIScriptLibAdjuster.setNewData(mHomeEntities);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}